/**
 * GreyscaleScheme.java
 * colourmap
 * Copyright (C) 2010 Alan W.F. Boyd
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * You can contact the author via the google code web page for the project
 * <http://colourmap.googlecode.com>
 */
package com.googlecode.colourmap.colours;

import java.awt.Color;

/**
 * An example greyscale colour scheme that provides a mapping of greys to data values.
 * Unlike other schemes, this example does not use a key.
 * 
 * @author Alan W.F. Boyd
 *
 */
public class GreyscaleScheme implements IColourScheme
{
	/** The maximum data value */
	private float max;
	
	/** The minimum data value */
	private float min;
	
	/**
	 * Returns the colour of the outline of the data points for the map
	 * @return the data points outline colour
	 */
	public Color getOutlineColour()
	{
		return Color.black;
	}
	
	/**
	 * Given a data value, this function returns the colour of that point.
	 * The colour is based on how close the supplied data value is to the maximum
	 * and minimum data values, respectively.
	 * @param f the data value
	 * @return the colour associated with the data value
	 */
	public Color getColour(float f)
	{
		if (f <= min)
			return new Color(0, 0, 0);
		else if (f >= max)
			return new Color(255, 255, 255);
		
		// Find out at what point between the max and min this value lies
		float maxDifference = max - min;
		float difference = (int)(f - min);
		int magnitude = (int)(difference*255/maxDifference);
		
		return new Color(magnitude, magnitude, magnitude);
	}

	/**
	 * Resets the maximum data value in a data set
	 * @param f the new maximum data value
	 */
	public void setMax(float f)
	{
		max = f;
	}

	/**
	 * Resets the minimum data value in a data set
	 * @param f the new minimum data value
	 */
	public void setMin(float f)
	{
		min = f;
	}	
}